package my.study.org.springframework.context.examples.example1.imp;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import my.study.org.springframework.context.examples.example1.interfaces.ConnectionManager;
/**
 * for connecting to the MySQL DataBase
 * @author fanhongjie
 * 
 */
public class ConnectionManagerImp implements ConnectionManager {
	private static final String driver = "com.mysql.jdbc.Driver";

	private Connection connection = null;
	
	public ConnectionManagerImp(String url, String urs, String psw) throws ClassNotFoundException, SQLException {
		this(url, urs, psw, driver);
	}
	
	public ConnectionManagerImp(String url, String urs, String psw, String driver) throws ClassNotFoundException, SQLException {
		getConnection(url, urs, psw, driver);
	}
	
	private void getConnection(String url, String urs, String psw, String driver) throws ClassNotFoundException, SQLException {
			Class.forName(driver);
			connection = DriverManager.getConnection(url, urs, psw);
			
	}
	
	public Connection getConnection() {
		return connection;
	}
}
